﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.aswingui {
    import flash.events.*;
    import flash.display.*;
    import flash.utils.*;
    import org.aswing.*;
    import Classes.*;
    import org.aswing.geom.*;
    import org.aswing.event.*;
    import org.aswing.border.*;
    import org.aswing.ext.*;

    public class VerticalScrollingList extends JPanel {

        public static const EVENT_UPDATEBUTTONS:String = "VerticalScrollingListEvent_UpdateButtons";

        protected var m_assetDict:Dictionary;
        protected var m_dataList:VectorListModel;
        protected var m_cellFactory:GridListCellFactory;
        protected var m_columns:int;
        protected var m_rows:int;
        protected var m_preferredWidth:int;
        protected var m_prefSize:IntDimension;
        protected var m_rounded:Boolean;
        protected var m_gridList:GridList;
        protected var m_navPanel:JPanel;
        protected var m_upButton:JButton;
        protected var m_downButton:JButton;
        protected var m_currentIndex:int;

        public function VerticalScrollingList(_arg1:Dictionary, _arg2:VectorListModel, _arg3:GridListCellFactory, _arg4:int=0, _arg5:int=0, _arg6:int=0, _arg7:int=0, _arg8:Boolean=false){
            super(new SoftBoxLayout(SoftBoxLayout.Y_AXIS, 0, SoftBoxLayout.TOP));
            this.m_assetDict = _arg1;
            this.m_dataList = _arg2;
            this.m_cellFactory = _arg3;
            this.m_columns = _arg4;
            this.m_rows = _arg5;
            this.m_prefSize = new IntDimension(_arg6, _arg7);
            this.m_rounded = _arg8;
            this.makeUI();
            ASwingHelper.prepare(this);
            this.m_currentIndex = 0;
        }
        public function get numElements():int{
            if (this.m_gridList.getModel()){
                return (this.m_gridList.getModel().getSize());
            };
            return (0);
        }
        protected function makeUI():void{
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.LEFT);
            this.m_gridList = new GridList(this.m_dataList, this.m_cellFactory, this.m_columns, 0);
            var _local2:JPanel = this.makeNavPanel();
            var _local3:JPanel = this.makeGridListPanel();
            _local1.appendAll(_local3, _local2);
            this.append(_local1);
        }
        protected function makeGridListPanel():JPanel{
            var _local2:int;
            var _local3:int;
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.TOP);
            this.m_gridList.setSelectable(false);
            this.m_gridList.setVGap(0);
            if (this.m_prefSize){
                _local2 = (this.m_prefSize.width - this.m_navPanel.getWidth());
                _local3 = this.m_prefSize.height;
                this.m_gridList.setPreferredWidth(_local2);
                this.m_gridList.setPreferredHeight(_local3);
                this.m_gridList.setTileWidth((_local2 / this.m_columns));
                this.m_gridList.setTileHeight((_local3 / this.m_rows));
            };
            this.dispatchEvent(new Event(EVENT_UPDATEBUTTONS));
            _local1.append(this.m_gridList);
            ASwingHelper.prepare(this.m_gridList);
            return (_local1);
        }
        protected function makeNavPanel():JPanel{
            var _local10:MarginBackground;
            this.m_navPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER);
            var _local1:DisplayObject = (new (this.m_assetDict["pic_dot"])() as DisplayObject);
            var _local2:DisplayObject = (new (this.m_assetDict["btn_up_normal"])() as DisplayObject);
            var _local3:DisplayObject = (new (this.m_assetDict["btn_up_down"])() as DisplayObject);
            var _local4:DisplayObject = (new (this.m_assetDict["btn_up_over"])() as DisplayObject);
            var _local5:DisplayObject = (new (this.m_assetDict["btn_down_normal"])() as DisplayObject);
            var _local6:DisplayObject = (new (this.m_assetDict["btn_down_down"])() as DisplayObject);
            var _local7:DisplayObject = (new (this.m_assetDict["btn_down_over"])() as DisplayObject);
            this.m_upButton = new JButton();
            this.m_upButton.wrapSimpleButton(new SimpleButton(_local2, _local4, _local3, _local2));
            this.m_upButton.addActionListener(this.moveUp, 0, true);
            var _local8:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            var _local9:AssetPane = new AssetPane(_local1);
            _local8.append(_local9);
            this.m_downButton = new JButton();
            this.m_downButton.wrapSimpleButton(new SimpleButton(_local5, _local7, _local6, _local5));
            this.m_downButton.addActionListener(this.moveDown, 0, true);
            addEventListener(EVENT_UPDATEBUTTONS, this.updateButtons, false, 0, true);
            this.m_gridList.addSelectionListener(this.updateButtons, 0);
            this.m_navPanel.appendAll(this.m_upButton, ASwingHelper.verticalStrut(50), _local8, ASwingHelper.verticalStrut(50), this.m_downButton);
            if (this.m_rounded){
                _local10 = new MarginBackground((new (this.m_assetDict["vertical_scrollBar_border"])() as DisplayObject));
                this.m_navPanel.setBackgroundDecorator(_local10);
            } else {
                this.m_navPanel.setBorder(new LineBorder(null, new ASColor(EmbeddedArt.lightBlueTextColor), 2));
            };
            ASwingHelper.prepare(this.m_navPanel);
            return (this.m_navPanel);
        }
        protected function moveUp(_arg1:AWEvent=null):void{
            _arg1.stopPropagation();
            _arg1.stopImmediatePropagation();
            if (this.m_currentIndex > 0){
                this.m_gridList.scrollVertical(-(this.m_gridList.getTileHeight()));
                this.m_currentIndex--;
            };
            this.dispatchEvent(new Event(EVENT_UPDATEBUTTONS));
        }
        protected function moveDown(_arg1:AWEvent=null):void{
            _arg1.stopPropagation();
            _arg1.stopImmediatePropagation();
            if (this.m_currentIndex < (this.numElements - this.m_rows)){
                this.m_gridList.scrollVertical(this.m_gridList.getTileHeight());
                this.m_currentIndex++;
            };
            this.dispatchEvent(new Event(EVENT_UPDATEBUTTONS));
        }
        private function updateButtons(_arg1:Event=null):void{
            this.m_upButton.setEnabled((this.m_currentIndex > 0));
            this.m_downButton.setEnabled((this.m_currentIndex < (this.numElements - this.m_rows)));
        }

    }
}//package Display.aswingui 
